define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'auth/admininfo/index',
                    add_url: 'auth/admininfo/add',
                    edit_url: 'auth/admininfo/edit',
                    del_url: 'auth/admininfo/del',
                    multi_url: 'auth/admininfo/multi',
					import_url: 'auth/admininfo/import',
                    table: 'admin_info',
                }
            });

            var table = $("#table");
			//在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='admin.department']", form).addClass("selectpage").data("source", "auth/department/index").data("primaryKey", "id").data("field", "name",'id').data("orderBy", "id desc").data("perPage","3");;

                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
						{field: 'userid', title: __('Userid')},
                        
						{field: 'weigh', title: __('Weigh'),sortable:true},
   
					     {field: 'admin.username', title: __('姓名'),operate:false},
                        {field: 'admin.mobile', title: __('手机号'),operate:false},
                        {field: 'admin.department_text', title: __('所属部门'),operate:false},
                        {field: 'admin.department', title: __('所属部门'), visible: false,formatter: Table.api.formatter.search},
                        {field: 'admin.id_number', title: __('身份证号'),operate:false},
						{field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        
						{field: 'status_week', title: __('Status_week'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        
						{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        
						{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        
						{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});